package org.dromara.system.controller.xiaofu;


import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.XfUserReview;
import org.dromara.system.domain.query.XfUserReviewQuery;
import org.dromara.system.domain.vo.XfUserReviewVo;
import org.dromara.system.service.IXfUserReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/xiaofu/userReview")
public class XfUserReviewController extends BaseController {

    @Autowired
    private IXfUserReviewService xfUserReviewService;

    @GetMapping("/list")
    public TableDataInfo<XfUserReviewVo> list(XfUserReviewQuery query){
        return xfUserReviewService.selectPageXfUserReviewList(query);
    }

    @GetMapping("/{id}")
    public R<XfUserReviewVo> getDetail(@PathVariable Long id){
        XfUserReviewVo xfUserReviewVo = xfUserReviewService.selectXfUserReviewById(id);
        return R.ok(xfUserReviewVo);
    }

    @PostMapping
    public R<Long> add(@RequestBody XfUserReview userReview){
        // 设置创建时间
        userReview.setCreatedAt(new java.util.Date());
        userReview.setUpdatedAt(new java.util.Date());
        // 设置默认状态为启用(1)
        userReview.setStatus(1);
        // 设置默认为非匿名
        if (userReview.getIsAnonymous() == null) {
            userReview.setIsAnonymous(0);
        }
        boolean result = xfUserReviewService.insertXfUserReview(userReview);
        if (result) {
            return R.ok(userReview.getId()); // 返回创建的评价ID
        }
        return R.fail();
    }

}
